#!/usr/bin/env python

# -*- coding: utf-8 -*

"""
Led灯，有红灯和蓝灯
"""

import logging
from py_code.driver.Pin import Pin
from py_code.SingletonType import SingletonType
from py_code.driver.GpioDriver import GpioDriver
import RPi.GPIO as GPIO


class Led(GpioDriver, metaclass=SingletonType):
    """LED的引脚（未测试）"""

    pins = [Pin(40, GPIO.OUT, description="red"), Pin(38, GPIO.OUT, description="blue")]

    """同样懒得写使用的函数了，直接调用pins，写入GPIO.HIGH来亮灯或者GPIO.LOW来熄灭灯"""

    def red(self, on: bool):
        pin = self.pins[0]
        if on:
            pin.writeHigh()
        else:
            pin.writeLow()
        logging.debug(f"红灯{'亮' if on else '灭'}")

    def blue(self, on: bool):
        pin = self.pins[1]
        if on:
            pin.writeHigh()
        else:
            pin.writeLow()
        logging.debug(f"蓝灯{'亮' if on else '灭'}")
